-module(fibtest).
-export([fib/1,fib_tail/1]).

fib([N]) ->
    N1 = list_to_integer(atom_to_list(N)),
    io:format( "fib(~w) = ~w~n", [N1,fib_tail(N1)] ),
    init:stop().

fib_c(0) ->
    1;
fib_c(1) ->
    1;
fib_c(N) ->
    fib_c(N-1) + fib_c(N-2).


fib_tail(N) ->
    fib_t1(1,1,N).

fib_t1(L2,L1,0) ->
    L2;
fib_t1(L2,L1,Acc) ->
    fib_t1(L1,L2+L1,Acc-1).

fib_t(L2,L1,Acc) ->
    case Acc of
	0 ->
	    L2;
	_ ->
	    fib_t(L1,L2+L1,Acc-1)
    end.
